﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entity;
using Utils.DC.Web.UI;
using System.IO;

public partial class Pages_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["loginClient"] != null)
        {
            Response.Redirect("../Pages/Home.aspx");
        }
        else
        {

        }
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        Customer cus=new Customer();
        cus = new CustomerUI().Login(txtUsername.Text.Trim(), Security.Encrypt(txtPassword.Text.Trim()));
         if (cus != null)
         {
             if (cus.C_Status)
             {
                 lblError.Visible = false;
                 Session["loginClient"] = cus;
                 string url = Server.MapPath("~/Upload/users");
                 if (!Directory.Exists(url + "/" + cus.Username))
                 {
                     Directory.CreateDirectory(url + "/" + cus.Username);
                 }
                 Response.Redirect("../Pages/Home.aspx");
             }
             else
             {
                 Session["loginClient"] = cus;
                 Response.Redirect("../Pages/AccountLock.aspx");
             }
         }
         else
         {
             lblError.Visible = true;
         }

    }
}
